
global user "dveracossio"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1  "$dirdata\Final data"
global dir2  "$dirdata\Results\graphs"
global dir3  "$dirdata\Results\"
cd "$dir3"

use "$dir1\pooled_hh_rob7-10.dta", clear
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1
drop tau
g Post=year>=2008
egen w_hoursw_head=rowtotal(w_hoursw_p w_hoursw_m)
g work_head=w_hoursw_head>0
replace work_head=. if work_m==. & work_p==. 
g min_7to8=min_schooling==7 | min_schooling==8
local sample1 "(min_schooling>=7 & min_schooling<=10)"
local nwork_lab "# of working adults"
local w_hoursw_t_lab "Hours/week"
local work_head_lab "Worked last week"
local w_hoursw_head_lab "Hours/week"
local work_m_lab "Worked last week"
local work_p_lab "Worked last week"
local w_hoursw_m_lab "Hours/week "
local w_hoursw_p_lab "Hours/week "
local parm c.Post#c.min_7to8
local replace replace


global covs1 "age spanish schooling hhmale  urban np nchild5  hhmale age_sac i.year"

global covs4 "age spanish schooling hhmale  urban np nchild5  hhmale age_sac  c.age_sac#i.year c.np#i.year i.departamento#i.year i.year"


local spec0  c.Post#c.min_7to8 i.min_schooling  i.year  

local spec4  c.Post#c.min_7to8 i.min_schooling  $covs4  


foreach x in  work_head w_hoursw_head nwork w_hoursw_t {
sum `x' [w=factor]  if year==2007 & `sample1'
local mean_dv=r(mean)
areg `x'  `spec4' [w=factor] if `sample1', a(departamento) cluster(municipio)
outreg2 using "$dir3\PTable2_7to8", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust),Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Demographic Controls, YES, Avg. age X year FE,  YES, HH size X year FE, YES, Region X year FE, YES )   
local replace append
}

****



global covs0 "i.year "
global covs1 "age_m spanish_m schooling_m age spanish schooling hhmale urban np nchild5 age_sac i.year "
global covs4 "age_m spanish_m schooling_m age spanish schooling hhmale urban np nchild5 age_sac  c.age_sac#i.year c.np#i.year  i.departamento#i.year i.year"

local spec4 `parm' i.min_schooling  $covs4  

local sample1 "(min_schooling>=7 & min_schooling<11)"





foreach x in work_m w_hoursw_m  {
foreach y in  4 {
sum `x' [w=factor]  if year==2007 & `sample1'
local mean_dv=r(mean)
areg `x'  `spec`y'' [w=factor] if `sample1',a(departamento) cluster(municipio)
estimates store r`x'`y'
outreg2 using "$dir3\PTable2_7to8", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) cttop(`top`y'') adds(Clusters, e(N_clust),Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Avg. age X year FE,  YES, HH size X year FE, YES )   
local replace append
}
}


global covs0 "i.year"
global covs1 "age_p spanish_p schooling_p age  spanish  schooling urban np nchild5  hhmale age_sac  i.year"
global covs4 "age_p spanish_p schooling_p age  spanish  schooling urban np nchild5  hhmale age_sac c.age_sac#i.year c.np#i.year  i.departamento#i.year i.year"
 

local spec4  `parm' i.min_schooling  $covs4  

local sample1 "(min_schooling>=7 & min_schooling<11)"


foreach x in work_p w_hoursw_p  {
foreach y in  4  {
sum `x' [w=factor]  if year==2007 & `sample1'
local mean_dv=r(mean)
areg `x'  `spec`y'' [w=factor] if `sample1',a(departamento) cluster(municipio)
outreg2 using "$dir3\PTable2_7to8", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) cttop(`top`y'') adds(Clusters, e(N_clust),Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Avg. age X year FE,  YES, HH size X year FE, YES )   
local replace append
}
}



